package src.itheima03;

import java.util.HashSet;

/*
    HashSet存储自定义Student对象
    步骤:
        1.定义标准的Student类
        2.创建HashSet集合对象,泛型Student
        3.HashSet集合对象调用add方法,添加多个Student对象
        4.遍历输出: 迭代器/增强for

     要求:
        HashSet/LinkedHashSet存储的元素所属的类要覆盖重写hashCode方法和equals方法
 */
public class Demo03HashSetStudent {
    public static void main(String[] args) {
        //2.创建HashSet集合对象,泛型Student
        HashSet<Student> set = new HashSet<>();

        //3.HashSet集合对象调用add方法,添加多个Student对象
        set.add(new Student("小军子",18));
        set.add(new Student("小军子",18));
        set.add(new Student("小文字",16));
        set.add(new Student("小文字",16));
        set.add(new Student("大亮子",17));
        set.add(new Student("大亮子",17));
        set.add(new Student("大欢子",19));
        set.add(new Student("大欢子",19));
        //4.遍历输出: 迭代器/增强for
        for (Student stu : set) {
            System.out.println(stu);
        }
    }
}
